﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for MemberDAL
/// </summary>
public class MemberDAL
{
    DataAccess acc = new DataAccess();
    public MemberDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    internal DataTable getAllMember()
    {
        return acc.executeSelect("gettAllMember");
    }

    internal bool updateMemberStatus(string memID)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = memID;
        int check = acc.executeModifier("updateMemberStatus", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal DataTable isValidLogin(string user, string pass)
    {
        SqlParameter[] paraList = new SqlParameter[2];
        paraList[0] = new SqlParameter("@M_UserName", SqlDbType.NVarChar, 200);
        paraList[0].Value = user;
        paraList[1] = new SqlParameter("@M_Password", SqlDbType.NVarChar, 200);
        paraList[1].Value = pass;
        return acc.executeSelect("validLoginMember", paraList);
    }

    internal DataTable checkEmail(string email)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@M_Mail", SqlDbType.NVarChar, 50);
        paraList[0].Value = email;
        return acc.executeSelect("getMemberByEmail", paraList);
    }

    internal bool ForgetPass(string email)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@M_Mail", SqlDbType.NVarChar, 50);
        paraList[0].Value = email;
        int check = acc.executeModifier("ForgetPassword", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal DataTable checkUser(string user)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@M_UserName", SqlDbType.NVarChar, 200);
        paraList[0].Value = user;
        return acc.executeSelect("checkUser", paraList);
    }

    internal DataTable checkID(string id)
    {
        SqlParameter[] paraList = new SqlParameter[1];
        paraList[0] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        return acc.executeSelect("checkID", paraList);
    }

    internal bool insertMember(string id, string fName, DateTime Bod, string gender, string phone, string address, string mail, string user, string pass)
    {
        SqlParameter[] paraList = new SqlParameter[9];
        paraList[0] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        paraList[1] = new SqlParameter("@M_FullName", SqlDbType.NVarChar, 50);
        paraList[1].Value = fName;
        paraList[2] = new SqlParameter("@M_Bob", SqlDbType.DateTime);
        paraList[2].Value = Bod;
        paraList[3] = new SqlParameter("@M_Gender", SqlDbType.NVarChar, 50);
        paraList[3].Value = gender;
        paraList[4] = new SqlParameter("@M_Phone", SqlDbType.NVarChar, 50);
        paraList[4].Value = phone;
        paraList[5] = new SqlParameter("@M_Address", SqlDbType.NVarChar, 4000);
        paraList[5].Value = address;
        paraList[6] = new SqlParameter("@M_Mail", SqlDbType.NVarChar, 50);
        paraList[6].Value = mail;
        paraList[7] = new SqlParameter("@M_UserName", SqlDbType.NVarChar, 200);
        paraList[7].Value = user;
        paraList[8] = new SqlParameter("@M_Password", SqlDbType.NVarChar, 200);
        paraList[8].Value = pass;

        int check = acc.executeModifier("InsertMember", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal bool updatePass(string memID, string pass)
    {
        SqlParameter[] paraList = new SqlParameter[2];
        paraList[0] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = memID;
        paraList[1] = new SqlParameter("@M_Password", SqlDbType.NVarChar, 200);
        paraList[1].Value = pass;
        int check = acc.executeModifier("updatePass", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    internal bool updateMember(string id, string fName, DateTime Bod, string gender, string phone, string address, string mail)
    {
        SqlParameter[] paraList = new SqlParameter[7];
        paraList[0] = new SqlParameter("@M_ID", SqlDbType.NVarChar, 50);
        paraList[0].Value = id;
        paraList[1] = new SqlParameter("@M_FullName", SqlDbType.NVarChar, 50);
        paraList[1].Value = fName;
        paraList[2] = new SqlParameter("@M_Bob", SqlDbType.DateTime);
        paraList[2].Value = Bod;
        paraList[3] = new SqlParameter("@M_Gender", SqlDbType.NVarChar, 50);
        paraList[3].Value = gender;
        paraList[4] = new SqlParameter("@M_Phone", SqlDbType.NVarChar, 50);
        paraList[4].Value = phone;
        paraList[5] = new SqlParameter("@M_Address", SqlDbType.NVarChar, 4000);
        paraList[5].Value = address;
        paraList[6] = new SqlParameter("@M_Mail", SqlDbType.NVarChar, 50);
        paraList[6].Value = mail;


        int check = acc.executeModifier("updateMember", paraList);
        if (check > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}